package fr.labri.macchiato.core.model;

import java.util.ArrayList;
import java.util.List;

import fr.labri.macchiato.core.model.utils.Address;
import fr.labri.macchiato.core.technical.Identifiable;

/**
 * A provider is an entity able to sell {@link Product}s.
 * 
 * This class maps the table businessEntity found <a href=http://www.heppnetz
 * .de/ontologies/goodrelations/goodrelations-UML.png>here</a> { Some fields has
 * been removed in order to have a clone of the schema of our database
 * "macchiato.n3"
 * 
 * @author Matthieu FOUCAULT
 * @author Michelle AVOMO
 * 
 */
public class BusinessEntity implements Identifiable<String> {

	// properties
	private String legalName;
	private String srcLogo;
	private String page;
	private Address addresse;
	private String Description;
	private List<Location> location;

	/**
	 * Default constructor
	 */
	BusinessEntity() {
	}

	/**
	 * Creates a provider with the given legalName
	 * 
	 * @param name
	 */
	public BusinessEntity(String name) {
		this.legalName = name;
	}

	/**
	 * creates a new {@link BusinessEntity} with the given name and logo
	 * 
	 * @param name
	 * @param logo
	 */
	public BusinessEntity(String name, String logo) {
		this.legalName = name;
		this.srcLogo = logo;
	}

	/**
	 * A business entity has a name and a logo
	 * 
	 * @param name
	 * @param urlLogo
	 * @param page
	 */
	public BusinessEntity(String name, String urlLogo, String page) {
		this.legalName = name;
		this.srcLogo = urlLogo;
		this.page = page;

		this.location = null;
	}

	/**
	 * Constructor with a legalName, a logo and a list of addresses or location
	 * 
	 * @param name
	 * @param urlLogo
	 * @param location
	 */
	public BusinessEntity(String name, String urlLogo, List<Location> location) {
		this.location = location;
		this.legalName = name;
		this.srcLogo = urlLogo;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof BusinessEntity)
			return ((BusinessEntity) obj).getId().equals(this.getId());
		else
			return false;
	}

	/**
	 * @return the url of the logo
	 */
	public String getSrcLogo() {
		return srcLogo;
	}

	/**
	 * @param srcLogo
	 *            : icon of a business entity
	 */
	public void setSrcLogo(String srcLogo) {
		this.srcLogo = srcLogo;
	}

	/**
	 * @return the list of location for a business entity
	 */
	public List<Location> getLocation() {
		return location;
	}

	/**
	 * @param location
	 *            the location to set
	 */
	public void setLocation(List<Location> location) {
		this.location = location;
	}

	/**
	 * @param location
	 *            the location to add
	 */
	public void addLocation(Location location) {
		if (this.location == null)
			this.location = new ArrayList<Location>();

		this.location.add(location);
	}

	/**
	 * @return the legalName
	 */
	public String getLegalName() {
		return legalName;
	}

	/**
	 * @param legalName
	 *            the legalName to set
	 */
	public void setLegalName(String legalName) {
		this.legalName = legalName;
	}

	/**
	 * @return the page
	 */
	public String getPage() {
		return page;
	}

	/**
	 * @param page
	 *            the page to set
	 */
	public void setPage(String page) {
		this.page = page;
	}

	/**
	 * @return the address of the business entity
	 */
	public Address getAddresse() {
		return addresse;
	}

	/**
	 * @param addresse
	 *            address of the business entity to be set
	 */
	public void setAddresse(Address addresse) {
		this.addresse = addresse;
	}

	/**
	 * @return the description : text about the business entity activity
	 */
	public String getDescription() {
		return Description;
	}

	/**
	 * @param description
	 *            : text about the business entity activity to be set
	 */
	public void setDescription(String description) {
		Description = description;
	}

	public String getId() {
		return getLegalName();
	}

}
